//-----------------------------------------------------------------------------
//	File: task_key.c
//	Author: xialing
//		a task for key
//-----------------------------------------------------------------------------

#include "task_key.h"

// task prio & stk & id
#define TASK_PRIO	80
OS_TID task_key_id;

static uint16_t key_trig;
static uint16_t key_hold;
static uint16_t key_down;
static uint16_t key_state;

//-----------------------------------------------------------------------------
//	task_key - a task for key
//-----------------------------------------------------------------------------
__task void task_key(void)
{
	configure_key_gpio();
	configure_led_gpio();

	while (1) {
		// get key status
		key_state = key_scan();
		key_trig = key_state ^ key_hold;
		key_hold = key_state;
		key_down = key_trig & key_hold;
		// key 1
		if (key_down & KEY_S1) {
			mgui_menu_back();
		}
		// key 2		
		if (key_down & KEY_S2) {
			mgui_menu_back();
		}

		os_dly_wait(10);
	}
}

//-----------------------------------------------------------------------------
//	task_key_create - task create for key
//-----------------------------------------------------------------------------
void task_key_create(void)
{
	task_key_id = os_tsk_create(task_key, TASK_PRIO);
}

